var gulp = require('gulp');
var stylus = require('gulp-stylus');
var jade = require('gulp-jade');
var nib = require('nib');
var browserSync = require('browser-sync').create();

process.on("uncaughtException", function(err) {
	console.log(err);
});

gulp.task('stylus', function() {
	var stylusOptions = {
        use: [nib()],
        "import" : ["nib"]
    };
	gulp.src(["./dev/css/**/*.styl"])
		.pipe(stylus(stylusOptions))
		.pipe(gulp.dest('./build/css'))
		.pipe(browserSync.stream());
});

gulp.task('jade', function() {
	gulp.src(["./dev/html/*.jade"])
		.pipe(jade())
		.pipe(gulp.dest("./build/"))
		.pipe(browserSync.stream());
});

gulp.task('image', function() {
    gulp.src('./dev/img/**.*')
  		.pipe(gulp.dest('./build/img'));
});


gulp.task('serve', [], function() {

    browserSync.init({
        server: "./build"
    });
    gulp.watch(["./dev/html/**/*.jade"], ['jade']);
	gulp.watch(["./dev/css/**/*.styl"], ['stylus']);
});


gulp.task('default', ['stylus', 'jade', 'image', 'serve']);
